﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using STLGROUP.Layers.Presentations.FormBase;
using STLGROUP.Layers.Common;
using STLGROUP.Layers.DataAccessLayers;

namespace QuanLyBanHang
{
    /// <summary>
    /// CF004 - Danh Muc Dan Toc
    /// </summary>
    public partial class CF004 : frmCatalogBase
    {
        #region Member variables

        private static int _idDanToc;

        #endregion

        #region Constructors

        public CF004()
        {
            InitializeComponent();
        }

        #endregion

        #region Protected Methods

        protected override void LoadData()
        {
            this._bindingSource.DataSource = Cache.Context.DM_DanToc;
            dgvDanToc.DataSource = _bindingSource;

            base.LoadData();
        }

        protected override void AddDataBinding()
        {
            txtMaDanToc.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "IDDanToc", true);
            txtTenDanToc.DataBindings.Add(Const.BIND_TEXT, _bindingSource, "TenDanToc", true);
            base.AddDataBinding();
        }

        #endregion

        #region Public Methods

        public static int GetIDDanToc()
        {
            return _idDanToc;
        }

        #endregion

        #region Events

        private void dgvDanToc_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 2)
                {
                    _idDanToc = int.Parse(dgvDanToc.CurrentRow.Cells[0].Value.ToString());

                    this.Close();
                }
                else
                {
                    _idDanToc = 0;
                }
            }
            catch
            {
                _idDanToc = 0;
            }
        } 

        #endregion
    }
}